fix(chainbase): strengthen signature length validation#27
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR implements three major feature areas: stricter signature validation with Osaka TVM support, configurable rate limiter blocking modes with per-IP coordination, event configuration initialization reordering, plugin version gating, and defensive null checks. The changes span 42 files across core transaction/block handling, rate limiting, configuration, and test infrastructure. ChangesSignature Size Validation with Osaka TVM Support
Rate Limiter Blocking/Non-Blocking Mode
Event Configuration Refactoring and Plugin Versioning
Defensive Improvements and Test Infrastructure
🎯 4 (Complex) | ⏱️ ~75 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
bf862a9 to
e1df760
Compare
922269a to
bc74d53
Compare
There was a problem hiding this comment.
1 issue found across 15 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="chainbase/src/main/java/org/tron/core/capsule/TransactionCapsule.java">
<violation number="1" location="chainbase/src/main/java/org/tron/core/capsule/TransactionCapsule.java:245">
P1: Do not require signatures to be exactly 65 bytes here; this breaks compatibility for valid signatures that include trailing bytes.
(Based on your team's feedback about preserving transaction signature compatibility by accepting signatures of at least 65 bytes.) [FEEDBACK_USED]</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
390e342 to
9a6c149
Compare
9a6c149 to
6d5fcce
Compare
There was a problem hiding this comment.
1 issue found across 13 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="framework/src/main/java/org/tron/core/net/messagehandler/PbftDataSyncHandler.java">
<violation number="1" location="framework/src/main/java/org/tron/core/net/messagehandler/PbftDataSyncHandler.java:179">
P1: Allowing 66–68 byte PBFT signatures here enables trailing-byte variants of the same signature to be counted as distinct votes, because quorum is deduplicated by raw signature bytes while recovery uses only the first 65 bytes.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Allowing 65-68 byte PBFT signatures permitted trailing-byte variants of the same physical signature to be counted as distinct votes: the quorum set was keyed by raw signature bytes while ECDSA recovery only consumes the first 65 bytes, so a single signer could submit padded copies and inflate their vote weight. Switch validPbftSign to count unique recovered SR addresses instead, and add a regression test exercising sigs padded to 65/66/67/68 bytes from the same signer. Also extract the signature length predicate into SignUtils.isValidLength to consolidate the six callsites that gate on the TVM Osaka bound.
769d945 to
14cfb24
Compare
Summary
ChainConstant.MIN_SIGNATURE_SIZE(65) andMAX_SIGNATURE_SIZE(68), and the check itself inSignUtils.isValidLength(int size, boolean osakaAllowed); a signature is rejected ifsize < MIN_SIGNATURE_SIZEor, post-Osaka,size > MAX_SIGNATURE_SIZETransactionCapsule.checkWeight,BlockCapsule.validateSignature,Wallet.getTransactionApprovedList,RelayService.checkHelloMessage,PbftBaseMessage.analyzeSignature,PbftDataSyncHandler.ValidPbftSignTask)Design notes
Size bound: 65..68 instead of strict 65
The post-Osaka window accepts
65..68bytes rather than enforcing a strict== 65. This is a deliberate compatibility compromise:r || s || v).MAX_SIGNATURE_SIZE = 68bounds the previously unbounded encoding window while remaining compatible with the historical data on chain.== 65check once the historical compatibility window is no longer needed. The bound is centralized inChainConstantand the check inSignUtils.isValidLength, so tightening becomes a one-line change.Predicate placement
The size check lives in
SignUtils.isValidLength(int size, boolean osakaAllowed)(crypto module), not inChainConstant:cryptomodule is reachable from every callsite (chainbase,consensus,framework).A companion helper
DynamicPropertiesStore.isAllowTvmOsaka()replaces the previous inlinegetAllowTvmOsaka() == 1Lso callers thread a boolean, not a long.PBFT quorum accounting
validPbftSignnow dedupes accepted votes by the recovered SR address rather than by raw signature bytes. This keeps quorum accounting robust regardless of the exact byte-level encoding of each submitted signature. A regression test (PbftDataSyncHandlerTest.testValidPbftSignDedupesByAddress) covers the path.Breaking changes
chainbasemodule public-method signatures changed to threadDynamicPropertiesStorethrough the size check:TransactionCapsule.checkWeight(Permission, List<ByteString>, byte[], List<ByteString>)(..., DynamicPropertiesStore)(extra trailing arg)TransactionCapsule.addSign(byte[], AccountStore)(byte[], AccountStore, DynamicPropertiesStore)checkWeightadditionally callsObjects.requireNonNull(dynamicPropertiesStore). All in-tree callers are updated. External JVM consumers of thechainbaseartifact (SDKs, signing services, third-party tools) must add the new argument; existing call sites will fail to compile rather than silently misbehave.Changed files
common/.../config/Parameter.javaMIN_SIGNATURE_SIZE/MAX_SIGNATURE_SIZEtoChainConstantcrypto/.../SignUtils.javaisValidLength(int, boolean)predicatechainbase/.../DynamicPropertiesStore.javaisAllowTvmOsaka()helperchainbase/.../TransactionCapsule.javaDynamicPropertiesStorethroughcheckWeight/addSign; enforce size bounds post-Osakachainbase/.../BlockCapsule.javavalidateSignatureframework/.../Wallet.javagetTransactionApprovedListframework/.../RelayService.javacheckHelloMessageframework/.../PbftDataSyncHandler.javaValidPbftSignTask; dedupe PBFT quorum by recovered SR addressframework/.../PbftMsgHandler.javaDynamicPropertiesStoreintoanalyzeSignatureconsensus/.../PbftBaseMessage.javaanalyzeSignatureconsensus/.../PbftMessageHandle.javaDynamicPropertiesStoreintoanalyzeSignatureactuator/.../TransactionUtil.javacheckWeightcall siteTest plan
TransactionCapsuleTest—checkWeightsize enforcement pre/post-OsakaBlockCapsuleTest— witness signature size enforcement pre/post-OsakaTransactionExpireTest—getTransactionApprovedListsize enforcement pre/post-OsakaTransactionUtilTest—getTransactionSignWeightsize enforcement post-OsakaPbftDataSyncHandlerTest— PBFT sign size enforcement post-Osaka; quorum dedup (testValidPbftSignDedupesByAddress)PbftMsgHandlerTest— PBFT message sign size enforcement post-OsakaRelayServiceTest— hello message sign size enforcement post-Osaka